package top.infopub.mgr.fia.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import top.infopub.enums.fia.IncomeSettlementModeEnum;
import top.infopub.enums.fia.PayBillTypeEnum;
import top.infopub.generic.GenericDao;
import top.infopub.generic.GenericServiceImpl;
import top.infopub.mgr.fia.dao.PayBillDao;
import top.infopub.mgr.fia.dao.PayBillDetailDao;
import top.infopub.mgr.fia.service.PayBillService;
import top.infopub.mgr.fia.vo.PayBillVo;
import top.infopub.mgr.flow.cnst.FlowTemplateEnum;
import top.infopub.model.fia.PayBill;
import top.infopub.security.vo.AuthorizationVO;
import top.infopub.util.IdFactory;

import java.math.BigDecimal;
import java.util.Date;

@Service
public class PayBillServiceImpl extends GenericServiceImpl<PayBill, String> implements
		PayBillService {
	@Autowired
	private PayBillDao payBillDao;
	
	@Autowired
	private PayBillDetailDao payBillDetailDao;
	
	@Override
	public GenericDao<PayBill, String> getDao() {
		return payBillDao;
	}

    @Override
    public Page<PayBillVo> selectPageByDomainWhere(Page<PayBillVo> page, PayBillVo payBillVo) {
        PageHelper.startPage(page.getPageNum(), page.getPageSize());
        return (Page<PayBillVo>)payBillDao.selectByDomainWhere(payBillVo);
    }

	@Override
	public PayBill setPayBillInfo(String proCode, IncomeSettlementModeEnum ism, BigDecimal willPayAmt,
								  BigDecimal actPayAmt, PayBillTypeEnum pbt, FlowTemplateEnum fte, String bizSguid,
								  AuthorizationVO vo) {
		PayBill payBill = new PayBill();
		payBill.setCodes(IdFactory.getUUIDUpper());
		payBill.setProCode(proCode);
		payBill.setSettlementMode(ism.getCode());
		payBill.setWillPayAmount(willPayAmt);
		payBill.setActPayAmount(actPayAmt);
		payBill.setAddBy(vo.getId());
		payBill.setAddTime(new Date());
		payBill.setUptBy(vo.getId());
		payBill.setUptTime(new Date());
		payBill.setPayType(pbt.getCode());
		payBill.setStatus("1");
		payBill.setBizTableName(fte.getSrcBizTable());
		payBill.setBizSguid(bizSguid);
		return payBill;
	}
}